<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 找出出现次数最多的字符
        let str = 'ashdabjdayabjfabwfaaucbiwbqiequebqibaicbaacaua'
        // 切割成单个字符
        // 需要临时变量统计次数
        // 逐一比较
        function findMax(str) {
            if (str.length == 1) {
                return str
            }
            let charObj = {}
            // 使用key的方式比较
            for(let i = 0; i < str.length; i++) {
                // 如果charObj对象内没有当前遍历的key,则赋值1,如果有则+1
                // charAt()返回指定位置字符串
                !charObj[str.charAt(i)] ? charObj[str.charAt(i)] = 1 : charObj[str.charAt(i)] += 1
            }
            console.log(charObj);
            let maxChar = '',
                maxValue = 1
            for(let k in charObj) {
                if (charObj[k] >= maxValue) {
                    maxChar = k
                    maxValue = charObj[k]
                }
            }
            return maxChar
        }
        console.log(findMax(str));
    </script>
</body>
</html>